home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CEDITOR_
/
CEDITORT.C
< prev
next >
Wrap
Text File
|
1990-06-10
|
6KB
|
239 lines
/******************************************************************************
CEditorTask.c
The EditorTask Class
Implements undo for cut, copy, paste, clear type and delete commands for
the CEditorPane class.
Written by Johan A. Goossens
CompuServe: 74010,2576
SUPERCLASS = CTask.c
******************************************************************************/
#include <Commands.h>
#include <CClipboard.h>
#include "CEditorTask.h"
extern CClipboard *gClipboard;
/******************************************************************************
IEditorTask
Initialize an EditorTask object.
FirstTaskIndex gives the index into the STR# 130 (STRtaskNames)
resource where the undo strings reside. Strings for cut, copy, paste,
clear,type and delete commands are required (and in that order).
firstTaskIndex gives the index for cut.
******************************************************************************/
void CEditorTask::IEditorTask(CEditorPane *theEditorPane,
int firstNameIndex,
long theCommand)
{
int index;
if (theCommand > cmdMyClear)
index = firstNameIndex + theCommand - cmdMyTyping + 4;
else
index = firstNameIndex + theCommand - cmdMyCut;
inherited::ITask(index);
itsCommand = theCommand;
itsEditorPane = theEditorPane;
hasData = FALSE;
}
/******************************************************************************
Dispose {OVERRIDE}
******************************************************************************/
void CEditorTask::Dispose()
{
if (hasData)
DisposHandle(itsBuffer);
inherited::Dispose();
}
/******************************************************************************
Do {OVERRIDE}
Perform the task.
******************************************************************************/
void CEditorTask::Do()
{
long dummy;
switch (itsCommand)
{
case cmdMyCut:
case cmdMyCopy:
itsEditorPane->GetSelection(&startSel, &end1Sel);
hasData = gClipboard->GetData('TEXT', &itsBuffer);
itsEditorPane->DoCommand(itsCommand);
break;
case cmdMyPaste:
itsEditorPane->GetSelection(&startSel, &end1Sel);
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
itsEditorPane->DoCommand(itsCommand);
itsEditorPane->GetSelection(&dummy, &end2Sel);
break;
case cmdMyClear:
itsEditorPane->GetSelection(&startSel, &end1Sel);
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
itsEditorPane->DoCommand(itsCommand);
break;
case cmdMyTyping:
itsEditorPane->GetSelection(&startSel, &end1Sel);
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
end2Sel = startSel + 1;
break;
case cmdMyDelete:
itsEditorPane->GetSelection(&startSel, &end1Sel);
if (startSel == end1Sel)
{
itsEditorPane->SetSelection(startSel - 1, startSel);
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
}
else
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
break;
}
}
/******************************************************************************
Type
Adjust the counter in a typing task.
******************************************************************************/
void CEditorTask::Typing(int offset)
{
end2Sel += offset;
}
/******************************************************************************
Undo {OVERRIDE}
Undo the command.
******************************************************************************/
void CEditorTask::Undo()
{
Boolean oldHasData;
Handle oldItsBuffer;
switch (itsCommand)
{
case cmdMyCut:
itsEditorPane->SetSelection(startSel, startSel);
itsEditorPane->DoCommand(cmdMyPaste);
itsEditorPane->SetSelection(startSel, end1Sel);
if (hasData)
gClipboard->PutData('TEXT', itsBuffer);
break;
case cmdMyCopy:
itsEditorPane->SetSelection(startSel, end1Sel);
if (hasData)
gClipboard->PutData('TEXT', itsBuffer);
break;
case cmdMyPaste:
itsEditorPane->SetSelection(startSel, end2Sel);
if (hasData)
itsEditorPane->SetSelectionHandle(itsBuffer);
else
itsEditorPane->DoCommand(cmdMyClear);
break;
case cmdMyClear:
itsEditorPane->SetSelection(startSel, startSel);
if (hasData)
itsEditorPane->SetSelectionHandle(itsBuffer);
break;
case cmdMyTyping:
itsEditorPane->ResetTyping();
itsEditorPane->SetSelection(startSel, end2Sel);
oldHasData = hasData;
oldItsBuffer = itsBuffer;
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
if (oldHasData)
{
itsEditorPane->SetSelectionHandle(oldItsBuffer);
DisposHandle(oldItsBuffer);
}
else
itsEditorPane->DoCommand(cmdMyClear);
break;
case cmdMyDelete:
if (startSel == end1Sel)
{
itsEditorPane->SetSelection(startSel - 1, startSel - 1);
itsEditorPane->SetSelectionHandle(itsBuffer);
itsEditorPane->SetSelection(startSel, startSel);
}
else
{
itsEditorPane->SetSelection(startSel, startSel);
itsEditorPane->SetSelectionHandle(itsBuffer);
}
break;
}
}
/******************************************************************************
Redo {OVERRIDE}
Redo the command.
******************************************************************************/
void CEditorTask::Redo()
{
Boolean oldHasData;
Handle oldItsBuffer;
switch (itsCommand)
{
case cmdMyCut:
case cmdMyCopy:
case cmdMyPaste:
case cmdMyClear:
itsEditorPane->SetSelection(startSel, end1Sel);
itsEditorPane->DoCommand(itsCommand);
break;
case cmdMyTyping:
itsEditorPane->SetSelection(startSel, end1Sel);
oldHasData = hasData;
oldItsBuffer = itsBuffer;
hasData = itsEditorPane->GetSelectionHandle(&itsBuffer);
if (oldHasData)
{
itsEditorPane->SetSelectionHandle(oldItsBuffer);
itsEditorPane->SetSelection(end2Sel, end2Sel);
DisposHandle(oldItsBuffer);
}
else
itsEditorPane->DoCommand(cmdMyClear);
break;
case cmdMyDelete:
if (startSel == end1Sel)
itsEditorPane->SetSelection(startSel - 1, startSel);
else
itsEditorPane->SetSelection(startSel, end1Sel);
itsEditorPane->DoCommand(cmdMyClear);
break;
}
}